#!/bin/bash
set -e

function info() {
echo Usage: `basename $0` [-s sample_name] [-p out_prefix] reads1.fq reads2.fq
exit 65
}

while getopts  ":s:p:" opts
do
        case  $opts  in
        s) sample_name=$OPTARG;;
		p) out_prefix=$OPTARG;;
        esac
done
shift $(($OPTIND - 1))



if [ $# -lt 2 ]; then info; fi


. /mnt/ilustre/app/medical/tools/.var

echo using $genome_name as the reference genome
echo genome assembly is: $genome_assembly
echo dbsnp version is: $dbsnp_version
echo java memory: $java_memory
echo snpeff database: $snpeff_db_version


read_group=\
@RG\\tID:${sample_name}\\tPL:ILLUMINA\\tSM:$sample_name


reads_seq_1=$1
reads_seq_2=$2

echo reads are: $reads_seq_1 and $reads_seq_2 2>>$log 1>&2
 
echo; echo; echo start bwa mem ...
$bwa mem -M -L 1000 -t 10 -R $read_group $ref_genome \
$reads_seq_1 \
$reads_seq_2 \
> $out_prefix.sam



echo; echo; echo 'picard sam->bam sort index fixmateinformation'
java -Xmx$java_memory $tmp -jar ${picard_path}FixMateInformation.jar \
I=$out_prefix.sam \
O=$out_prefix.sort.bam \
SORT_ORDER=coordinate \
CREATE_INDEX=true




